//
//  UserInterfaceVC.swift
//  PBHome
//
//  Created by 曹连华 on 2020/12/21.
//

import UIKit
import ServiceCode

@available(iOS 13.0, *)
@objc public class UserInterfaceVC: BaseVC {
    lazy var lightBtn : UIButton = {
        let btn = UIButton(frame: CGRect(x: 30, y:100, width: 50, height: 40))
        btn.setTitle("light", for: .normal)
        btn.backgroundColor = ThemeColorManager.hexs("#2589FF")
        btn.addTarget(self, action: #selector(lightBtnAction), for: .touchUpInside)
        return btn
    }()
    lazy var darkBtn : UIButton = {
        let btn = UIButton(frame: CGRect(x: 100, y:100, width: 50, height: 40))
        btn.setTitle("dark", for: .normal)
        btn.backgroundColor = ThemeColorManager.hexs("#2589FF")
        btn.addTarget(self, action: #selector(darkBtnAction), for: .touchUpInside)
        return btn
    }()
    lazy var unspecifiedBtn : UIButton = {
        let btn = UIButton(frame: CGRect(x: 170, y:100, width: 50, height: 40))
        btn.setTitle("unspecified", for: .normal)
        btn.backgroundColor = ThemeColorManager.hexs("#2589FF")
        btn.addTarget(self, action: #selector(unspecifiedBtnAction), for: .touchUpInside)
        return btn
    }()
    public override func viewDidLoad() {
        super.viewDidLoad()
        self.initUI()
    }
    func initUI() {
        self.navigationItem.title = "切换模式"
        self.view.backgroundColor = UIColor.init(dynamicProvider: { (traitCollection) -> UIColor in
            if traitCollection.userInterfaceStyle == .dark {
                return UIColor.gray
            } else {
                return UIColor.white
            }
        })
        self.view.addSubview(self.unspecifiedBtn)
        self.view.addSubview(self.lightBtn)
        self.view.addSubview(self.darkBtn)
    }
    @objc func lightBtnAction(_ btn : UIButton) {
        if #available(iOS 13.0, *) {
            UserInterfaceMagager.updateUserInterfaceStyle(.light)
        } else {
            // Fallback on earlier versions
        }
    }
    @objc func darkBtnAction(_ btn : UIButton) {
        if #available(iOS 13.0, *) {
            UserInterfaceMagager.updateUserInterfaceStyle(.dark)
        } else {
            // Fallback on earlier versions
        }
    }
    @objc func unspecifiedBtnAction(_ btn : UIButton) {
        if #available(iOS 13.0, *) {
            UserInterfaceMagager.updateUserInterfaceStyle(.unspecified)
        } else {
            // Fallback on earlier versions
        }
    }
    

}
